<template>
  <div class="scadaBox">
    <img :src="scadaImg" class="imgBox" />
    <h1 class="title">{{ scada.name }}</h1>
    <p>创建时间：{{ getTime(scada.createTime) }}</p>
    <p>备注：{{ scada.detail }}</p>
    <div class="footer">
      <div class="opreation" @click="set">
        <span
          ><i style="color: #1f7ad5" class="iconfont icon-shezhi1"></i>设置<i class="break"
            >|</i
          ></span
        >
      </div>
      <!-- <div @click="copy" class="opreation"><span><i style="color:#22B4DD" class="iconfont icon-icon_fuzhi"></i>复制<i class="break">|</i></span></div> -->
      <div class="opreation" @click="preview">
        <span
          ><i style="color: #11a57c" class="iconfont icon-yulan1"></i>预览<i class="break"
            >|</i
          ></span
        >
      </div>
      <div class="opreation" @click="del">
        <span><i style="color: #ff5722" class="iconfont icon-shanchu"></i>删除</span>
      </div>
    </div>
    <div class="editScada">
      <i style="color: #fff" class="iconfont icon-bianji" @click="editScada"></i>
    </div>
  </div>
</template>

<script>
import scadaImg from '@/assets/other/scada-pc.png'
import moment from 'moment'
import useGlobal from '@/hooks/global/useGlobal'
const { $confirm } = useGlobal()
export default {
  // eslint-disable-next-line vue/require-prop-types
  props: ['scada'],
  data() {
    return { scadaImg, scadaUrl: this.$store.state.app.scadaUrl }
  },

  methods: {
    set() {
      this.$emit('set', this.scada)
    },
    copy() {
      this.$emit('copy', this.scada.dashBoardId)
    },
    del() {
      // 删除
      $confirm('确定删除该组态, 是否继续?', '删除提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          //   删除方法
          this.$emit('del', this.scada.dashBoardId)
        })
        .catch(() => {
          //
        })
    },
    preview() {
      // 预览
      const path = this.scadaUrl + 'viewer/' + this.scada.dashBoardId
      window.open(path)
    },
    editScada() {
      // 编辑
      const path =
        this.scadaUrl +
        'app/editor/' +
        this.scada.dashBoardId +
        '?token=' +
        this.$store.state.user.scadaToken
      console.log(this.$store.state.user.scadaToken, this.scada, path)
      window.open(path)
      console.log('编辑 绕登陆才行', this.scada, path)
    },
    getTime(val) {
      return moment(val).format('YYYY-MM-DD')
    }
  }
}
</script>

<style lang="scss" scoped>
.scadaBox {
  &:hover {
    box-shadow: 0 0 8px #036ced;
  }
  position: relative;
  &:hover {
    // box-shadow: 10px 10px 4px #3796fb;
    .editScada {
      visibility: visible;
    }
  }
  .editScada {
    cursor: pointer;
    position: absolute;
    top: 16px;
    right: 16px;
    visibility: hidden;
  }
  .imgBox {
    width: 100%;
    height: 168px;
  }
  .title {
    height: 22px;
    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 22px;
    text-align: center;
    margin: 8px 0;
  }
  p {
    padding: 0 12px;
    height: 20px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
    margin-bottom: 8px;
  }
  .footer {
    width: 100%;
    height: 35px;
    background: #f5f7fa;
    line-height: 35px;
    font-size: 12px;
    text-align: center;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
    cursor: pointer;
    display: flex;
    .opreation {
      position: relative;
      width: 25%;
      .break {
        position: absolute;
        right: 0;
        // top: 10px;
        font-size: 16px;
        color: #e6e6e6;
        font-style: normal;
      }
    }
  }
}
</style>
